/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2008-2011, Salzburg Research. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * - Neither the name of the KiWi Project nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributor(s):
 * sschaffe
 *
 * File Info:
 * User: sschaffe
 * Date: 2011/01/17
 * Time: 13:05
 *
 * Project: KiWi2, kiwi-core module
 */

package kiwi.core.api.sesame;

import kiwi.core.model.rdf.KiWiTriple;
import kiwi.core.model.rdf.KiWiUriResource;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;

import java.util.Set;

/**
 * The KiWi Sesame service allows interacting with the KiWi triple store using Sesame data. At the moment, the
 * service offers methods to import data from a Sesame repository into the KiWi triple store and to export a
 * set of triples into a Sesame repository.
 *
 * <p/>
 * User: sschaffe
 */
public interface KiWiSesameService {

    /**
     * Import the triples that are contained in the repository passed as argument into the KiWi triple store.
     * Triples that do not exist yet will be created as new. Note that while the transaction is not yet committed,
     * the triples are not yet persisted in the database. This Method create for every NamedGraph in the Repository
     * a own OntologySpace (kind of Knowledgespace) where the triple stores. If the triple has not a context it will
     * choose the defaultspace. Returns a Set containing the imported triples in
     * KiWi format.
     *
     *
     * @param connection
     * @return
     */
    public Set<KiWiTriple> importFromSesame(RepositoryConnection connection);

    /**
     * Import the triples that are contained in the repository passed as argument into the KiWi triple store.
     * Triples that do not exist yet will be created as new. Note that while the transaction is not yet committed,
     * the triples are not yet persisted in the database. If the triple has not a context it will
     * choose the defaultspace. Returns a Set containing the imported triples in
     * KiWi format. This method doesnt create a knowledgespace type for every given context.
     *
     *
     * @param connection
     * @return
     */
    public Set<KiWiTriple> importFromSesameWithoutSpaceCreation(RepositoryConnection connection);

    /**
     * Export the triples passed as first argument into the Sesame repository passed as second argument.
     *
     * @param triples
     * @param repository
     */
    public void exportToSesame(Iterable<KiWiTriple> triples, Repository repository);


    /**
     * Import the triple from the Repository like importFromSesame(). Only the context is different. It will
     * choose the context of the given space for every triple.
     *
     * @param connection
     * @param space
     * @return
     */
    public Set<KiWiTriple> importFromSesameInOwnSpace(RepositoryConnection connection, KiWiUriResource space);


    /**
     * Import the triples that are contained in the repository passed as argument into the KiWi triple store.
     * Triples that do not exist yet will be created as new. Note that while the transaction is not yet committed,
     * the triples are not yet persisted in the database. This method put the triple with context in the database
     * without checking for a valid context. If the triple has not a context it will choose the defaultspace. Returns a Set containing the imported triples in
     * KiWi format.
     *
     *
     * @param connection
     * @return
     */
    public Set<KiWiTriple> importFromSesameIgnorSpaces(RepositoryConnection connection);
}
